home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvmouse.exe / TVEDIT3.CPP < prev   
C/C++ Source or Header  |  1992-06-10  |  7KB  |  190 lines

  1. /*----------------------------------------------------------*/
  2. /*                                                          */
  3. /*   Turbo Vision 1.0                                       */
  4. /*   Copyright (c) 1991 by Borland International            */
  5. /*                                                          */
  6. /*   Turbo Vision TVEDIT source file                        */
  7. /*----------------------------------------------------------*/
  8.  
  9. #define Uses_TApplication
  10. #define Uses_TMenuBar
  11. #define Uses_TRect
  12. #define Uses_TSubMenu
  13. #define Uses_TKeys
  14. #define Uses_TMenuItem
  15. #define Uses_TStatusLine
  16. #define Uses_TStatusItem
  17. #define Uses_TStatusDef
  18. #define Uses_TPoint
  19. #define Uses_TEditor
  20. #define Uses_MsgBox
  21. #define Uses_TFileDialog
  22. #define Uses_TDeskTop
  23.  
  24. #include <tv.h>
  25.  
  26. #include "tvedit.h"
  27.  
  28. #include <stdarg.h>
  29. #include <strstrea.h>
  30. #include <iomanip.h>
  31.  
  32. TMenuBar *TEditorApp::initMenuBar( TRect r )
  33. {
  34.  
  35.       TSubMenu& sub1 = *new TSubMenu( "~F~ile", kbAltF ) +
  36.         *new TMenuItem( "~O~pen", cmOpen, kbF3 ) +
  37.         *new TMenuItem( "~N~ew", cmNew, kbNoKey ) +
  38.         *new TMenuItem( "~S~ave", cmSave, kbF2, hcNoContext, "F2" ) +
  39.         *new TMenuItem( "S~a~ve as...", cmSaveAs, kbNoKey ) +
  40.              newLine() +
  41.         *new TMenuItem( "~C~hange dir...", cmChangeDrct, kbNoKey ) +
  42.         *new TMenuItem( "~D~OS shell", cmDosShell, kbNoKey ) +
  43.         *new TMenuItem( "E~x~it", cmQuit, kbAltX, hcNoContext, "Alt-X" );
  44.  
  45.       TSubMenu& sub2 = *new TSubMenu( "~E~dit", kbAltE ) +
  46.         *new TMenuItem( "~U~ndo", cmUndo, kbNoKey ) +
  47.              newLine() +
  48.         *new TMenuItem( "Cu~t~", cmCut, kbShiftDel, hcNoContext, "Shift-Del" ) +
  49.         *new TMenuItem( "~C~opy", cmCopy, kbCtrlIns, hcNoContext, "Ctrl-Ins" ) +
  50.         *new TMenuItem( "~P~aste", cmPaste, kbShiftIns, hcNoContext, "Shift-Ins" ) +
  51.         *new TMenuItem( "~S~how clipboard", cmShowClip, kbNoKey ) +
  52.              newLine() +
  53.         *new TMenuItem( "~C~lear", cmClear, kbCtrlDel, hcNoContext, "Ctrl-Del" );
  54.  
  55.       TSubMenu& sub3 = *new TSubMenu( "~S~earch", kbAltS ) +
  56.         *new TMenuItem( "~F~ind...", cmFind, kbNoKey ) +
  57.         *new TMenuItem( "~R~eplace...", cmReplace, kbNoKey ) +
  58.         *new TMenuItem( "~S~earch again", cmSearchAgain, kbNoKey );
  59.  
  60.       TSubMenu& sub4 = *new TSubMenu( "~W~indows", kbAltW ) +
  61.         *new TMenuItem( "~S~ize/move",cmResize, kbCtrlF5, hcNoContext, "Ctrl-F5" ) +
  62.         *new TMenuItem( "~Z~oom", cmZoom, kbF5, hcNoContext, "F5" ) +
  63.         *new TMenuItem( "~T~ile", cmTile, kbNoKey ) +
  64.         *new TMenuItem( "C~a~scade", cmCascade, kbNoKey ) +
  65.         *new TMenuItem( "~N~ext", cmNext, kbF6, hcNoContext, "F6" ) +
  66.         *new TMenuItem( "~P~revious", cmPrev, kbShiftF6, hcNoContext, "Shift-F6" ) +
  67.         *new TMenuItem( "~C~lose", cmClose, kbAltF3, hcNoContext, "Alt-F3" );
  68.  
  69.     r.b.y = r.a.y+1;
  70.     return new TMenuBar( r, sub1 + sub2 + sub3 + sub4 );
  71. }
  72.  
  73. TStatusLine *TEditorApp::initStatusLine( TRect r )
  74. {
  75.     r.a.y = r.b.y-1;
  76.     return new TStatusLine( r,
  77.         *new TStatusDef( 0, 0xFFFF ) +
  78.             *new TStatusItem("~F2~ Save", kbF2, cmSave ) +
  79.             *new TStatusItem( "~F3~ Open", kbF3, cmOpen ) +
  80.             *new TStatusItem( "~Alt-F3~ Close", kbAltF3, cmClose ) +
  81.             *new TStatusItem( "~F5~ Zoom", kbF5, cmZoom ) +
  82.             *new TStatusItem( "~F6~ Next", kbF6, cmNext ) +
  83.             *new TStatusItem( "~F10~ Menu", kbF10, cmMenu ) +
  84.             *new TStatusItem( 0, kbCtrlF5, cmResize )
  85.             );
  86.  
  87. }
  88.  
  89. void TEditorApp::outOfMemory()
  90. {
  91.     messageBox("Not enough memory for this operation.", mfError | mfOKButton );
  92. }
  93.  
  94. typedef char *_charPtr;
  95. typedef TPoint *PPoint;
  96.  
  97. #pragma warn -rvl
  98.  
  99. ushort doEditDialog( int dialog, ... )
  100. {
  101.     va_list arg;
  102.  
  103.     char buf[80];
  104.     ostrstream os( buf, sizeof( buf ) );
  105.     switch( dialog )
  106.         {
  107.         case edOutOfMemory:
  108.             return messageBox( "Not enough memory for this operation",
  109.                                mfError | mfOKButton );
  110.         case edReadError:
  111.             {
  112.             va_start( arg, dialog );
  113.             os << "Error reading file " << va_arg( arg, _charPtr )
  114.                << "." << ends;
  115.             va_end( arg );
  116.             return messageBox( buf, mfError | mfOKButton );
  117.             }
  118.         case edWriteError:
  119.             {
  120.             va_start( arg, dialog );
  121.             os << "Error writing file " << va_arg( arg,_charPtr )
  122.                << "." << ends;
  123.             va_end( arg );
  124.             return messageBox( buf, mfError | mfOKButton );
  125.             }
  126.         case edCreateError:
  127.             {
  128.             va_start( arg, dialog );
  129.             os << "Error creating file " << va_arg( arg, _charPtr )
  130.                << "." << ends;
  131.             va_end( arg );
  132.             return messageBox( buf, mfError | mfOKButton );
  133.             }
  134.         case edSaveModify:
  135.             {
  136.             va_start( arg, dialog );
  137.             os << va_arg( arg, _charPtr )
  138.                << " has been modified. Save?" << ends;
  139.             va_end( arg );
  140.             return messageBox( buf, mfInformation | mfYesNoCancel );
  141.             }
  142.         case edSaveUntitled:
  143.             return messageBox( "Save untitled file?",
  144.                                mfInformation | mfYesNoCancel );
  145.         case edSaveAs:
  146.             {
  147.             va_start( arg, dialog );
  148.             return execDialog( new TFileDialog( "*.*",
  149.                                                 "Save file as",
  150.                                                 "~N~ame",
  151.                                                 fdOKButton,
  152.                                                 101 ), va_arg( arg, _charPtr ) );
  153.             }
  154.  
  155.         case edFind:
  156.             {
  157.             va_start( arg, dialog );
  158.             return execDialog( createFindDialog(), va_arg( arg, _charPtr ) );
  159.             }
  160.  
  161.         case edSearchFailed:
  162.             return messageBox( "Search string not found.",
  163.                                mfError | mfOKButton );
  164.         case edReplace:
  165.             {
  166.             va_start( arg, dialog );
  167.             return execDialog( createReplaceDialog(), va_arg( arg, _charPtr ) );
  168.             }
  169.  
  170.         case edReplacePrompt:
  171.             //  Avoid placing the dialog on the same line as the cursor
  172.             TRect r( 0, 1, 40, 8 );
  173.             r.move( (TProgram::deskTop->size.x-r.b.x)/2, 0 );
  174.             TPoint t = TProgram::deskTop->makeGlobal( r.b );
  175.             t.y++;
  176.             va_start( arg, dialog );
  177.             TPoint *pt = va_arg( arg, PPoint );
  178.             if( pt->y <= t.y )
  179.                 r.move( 0, TProgram::deskTop->size.y - r.b.y - 2 );
  180.             va_end( arg );
  181.             return messageBoxRect( r, "Replace this occurence?",
  182.                                    mfYesNoCancel | mfInformation );
  183.  
  184.         }
  185. }
  186.  
  187. #pragma warn .rvl
  188.  
  189.  
  190.